/**
 * Created by gmj on 8/27/16.
 */
var host = 'http://120.55.161.117:8080';
var token;
var username;

$("#regSub").click(function () {

    var username = $.base64.encode($("#username").val());
    var password = $.base64.encode($("#password").val());
    var email = $.base64.encode($("#email").val());
    var request = {
            "username": username,
            "password": password,
            "email": email,
            "weibo": $("#weibo").val(),
            "weixin": $("#weixin").val(),
        };
    var uri = "/portal/register";
    $.ajax({
        url: host + uri,
        method: "post",
        dataType: "json",
        contentType: 'application/json; charset=UTF-8',
        data: $.toJSON(request),
        success: function (data) {
            console.log(data);
        }
    
    });
});

$("#loginSub").click(function () {
    var username = $.base64.encode($("#login_username").val());
    var password = $.base64.encode($("#login_password").val());
    var uri = '/portal/login';
    var request = {
            "username": username,
            "password": password,
        };
    $.ajax({
        url: host + uri,
        method: "post",
        dataType: "json",
        contentType: 'application/json; charset=UTF-8',
        data: $.toJSON(request),
        success: function (data) {
            console.log(data);
            var res = data['res'];
            token = data['token'];
            username = data['username'];
            if(res == "success"){
                $("#bef_login").attr("style", "display: none;");
                $("#af_login").attr("style", "display: block;float: left");
                $("#af_username").append(data['username']);
            }
        }
    });
});
console.log(token);
console.log(username);
// if(token != ""){
//     $("#bef_login").attr("style", "display: none;");
//     $("#af_login").attr("style", "display: block;float: left");
//     $("#af_username").append(username);
// }else{
//     $("#bef_login").attr("style", "display: block;float:left;");
//     $("#af_login").attr("style", "display: none;float: left");
//     // $("#af_username").append(data['username']);
// }


